package com.adv.io;

import java.io.*;
import java.util.*;

/**
 * 6：把 1-10000内的所有质数 写入一个data.txt中，10个一行
 * 
 * @author zhaoyang
 *
 */
public class IO_Work06 {

	public static void main(String[] args) throws IOException {
		BufferedWriter bw = new BufferedWriter(new FileWriter("Date.txt"));
		int count = 0;
		for (int i = 2; i <= 10000; i++) {
			int j;
			for (j = 2; j * j < i && i % j != 0; j++)
				;
			if (j * j > i) {

				if (i < 10) {
					bw.append("   ");
				} else if (i < 100) {
					bw.append("  ");
				} else if (i < 1000) {
					bw.append(" ");
				}
				bw.append(i + " ");
				count++;
				if (count % 10 == 0) {
					bw.append("\r\n");
				}
			}
		}
		bw.close();
		System.out.println(">>>>>>>>>>>>>>>");
		BufferedReader br = new BufferedReader(new FileReader("Date.txt"));
		String str2 = null;
		while ((str2 = br.readLine()) != null) {
			System.out.println(str2);
		}
		br.close();
	}

}
